VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Cafe1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
'Project:  EightInchLabel
'Module:   EightInchLabel.Cafe
'Date:     8/12/2004
'Author:        Joseph Weir
'Version:
'Purpose   : Perform Cafe transactional operations
'
' 2009-07-21, Introduced to Array.
' 2010-03-01, Custom doc tab in here, for Fujitsu.
'

Option Explicit

' Enable BBB label in this standalone version of project (i.e. without import integration)
Const Canadian_BBB As Boolean = False
' For refs and message option
Dim m_strMessage As String
' Sig Reqd function have been started.
Public boolSigReqdStarted As Boolean
' Integration (Cafe AfterShipment) may turn sig reqd on and off.
Public boolSigReqdIntegration As Boolean
' Cntrl-F3 toggles sig reqd label
Public boolSigReqdShipper As Boolean
' 2011-02-01, JFW, Batch processing next shipment only after current label is out there
Public g_boolAfterLabel As Boolean
' 2011-02-18, JFW, Group ship requires improved handling of multiple label files
Dim WithEvents timerCleanup As Timer
Attribute timerCleanup.VB_VarHelpID = -1
Dim m_dtCleanup As Date
Dim m_strTrackingNumber As String           ' First piece tracking number
'


'+
' 2008-10-01, JFW, Provide helper routines for use by Integrations
'
Public Sub AfterShipment(TrackingNumber As String)

    Dim objTable As Table
    Dim i As Long
    
    On Error GoTo ErrorExit
    
    ' Logfile "EightInchLabel.Cafe.AfterShipment", TrackingNumber
    
    Set objTable = Cafe1.Databases.ExecDirect("select 29 from Shipment where 1123 = '" & TrackingNumber & "'")
    For i = 0 To objTable.Records.Count - 1
        Call Cafe_AfterShipPackage(objTable.Records(i).Fields("29").Value, "", True)
    Next i
    Call Cafe_AfterShipment(TrackingNumber, True)
    Exit Sub
    
ErrorExit:
    MsgBox Err.Description & " " & Err.Number, vbCritical, "EightInchLabel.Cafe.AfterShipment"

End Sub
'

Public Sub ClearPickLabel()

    modLabel8.m_udtPickTicket.PicRef1Cap = ""
    modLabel8.m_udtPickTicket.PicRef1 = ""
    modLabel8.m_udtPickTicket.PicRef2 = ""
    modLabel8.m_udtPickTicket.PicRef3 = ""
    modLabel8.m_udtPickTicket.PicRef4 = ""

    m_strMessage = ""
    
End Sub
'

Public Sub SetPickLabel(strRef() As Variant)

    modLabel8.m_udtPickTicket.PicRef1Cap = "From:"
    modLabel8.m_udtPickTicket.PicRef1 = strRef(0)
    modLabel8.m_udtPickTicket.PicRef2 = strRef(1)
    modLabel8.m_udtPickTicket.PicRef3 = strRef(2)
    modLabel8.m_udtPickTicket.PicRef4 = strRef(3)

    m_strMessage = "From:" & "^" _
        & strRef(0) & "^" & strRef(1) _
        & "^" & strRef(2) & "^" & strRef(3)

End Sub
'
'~

'
Public Function SignatureRequiredStyle() As Long

    If Not boolSigReqdIntegration Then
        ' Integration may turn sig req on or off
    ElseIf Not boolSigReqdShipper Then
        ' Shipper may toggle, no sig reqd
    ElseIf True Or Cafe1.Meter = "123456" Then
        ' Original label text
        SignatureRequiredStyle = 1
    ElseIf True Or Cafe1.Meter = "123456" Then
        ' Amex, Fujitsu
        SignatureRequiredStyle = 2
    End If
    
End Function
'

Public Sub ZplCustomLabel(strTrackingNumber As String, ByRef m_strLineItem As String)

    On Error GoTo EH
    
    Dim objTable As Table
    Dim strFreightCost As String
    
    '+
    ' Tracking number only, barcode on doctab
    If Cafe1.Meter = "123456" Then
        m_strLineItem = m_strLineItem & "^FO60,20^AdN,10,10^FWN^FH^FD" & strTrackingNumber & "^FS" & vbCrLf
        m_strLineItem = m_strLineItem & "^FO50,40^BY2,2,0^BCN,75,N,N,N,N^FWN^FD" & strTrackingNumber & "^FS" & vbCrLf
    End If
    '~
    
    '+
    ' Fujitsu Tracking number plus right-hand column
    If Cafe1.Meter = "123456" Then
        Set objTable = Cafe1.Databases.Shipment("21,34,35,36,37,75").Lookup(strTrackingNumber)
                       
        m_strLineItem = m_strLineItem & "^FO60,20^AdN,0,0^FWN^FH^FD" & strTrackingNumber & "^FS" & vbCrLf
        m_strLineItem = m_strLineItem & "^FO50,40^BY2,2,0^BCN,75,N,N,N,N^FWN^FD" & strTrackingNumber & "^FS" & vbCrLf
        
        strFreightCost = Val(objTable.Records(0).Fields("34").Value) - Val(objTable.Records(0).Fields("36").Value)
        
        m_strLineItem = m_strLineItem & "^FO540,20^AdN,0,0^FWN^FH^FDWEIGHT:    " & Right("     " & Format(Val(objTable.Records(0).Fields("21").Value), "0.00"), 8) & " " & objTable.Records(0).Fields("75").Value & "^FS" & vbCrLf
        m_strLineItem = m_strLineItem & "^FO540,42^AdN,0,0^FWN^FH^FDSHIPPING:  " & Right("     " & Format(Val(strFreightCost), "0.00"), 8) & "^FS" & vbCrLf
        m_strLineItem = m_strLineItem & "^FO540,64^AdN,0,0^FWN^FH^FDSPECIAL:   " & Right("     " & Format(Val(objTable.Records(0).Fields("35").Value), "0.00"), 8) & "^FS" & vbCrLf
        m_strLineItem = m_strLineItem & "^FO540,86^AdN,0,0^FWN^FH^FDTOTAL:     " & Right("     " & Format(Val(objTable.Records(0).Fields("37").Value), "0.00"), 8) & "^FS" & vbCrLf
    End If
    '~
    
    ' 2010-11-26, JFW, Customer specific 8 inch label, Megalak
    If Cafe1.Meter = "123456" Then
    
        ' Logfile "ZplCustomLabel", "TrackingNumber: " & strTrackingNumber
        
        Set objTable = Cafe1.Databases.Shipment("2006,3059").Lookup(strTrackingNumber)
        m_strLineItem = m_strLineItem & "^FO55,330^AdN,30,10^FWN^FH^FD" & objTable.Records(0).Fields("2006").Value & "^FS" & vbCrLf
        'Replaced message field with SortID
        If Len(objTable.Records(0).Fields("3059").Value) <= 5 Then
            m_strLineItem = m_strLineItem & "^FO10,20^A0N,500,325^FWN^FH^FD" & objTable.Records(0).Fields("3059").Value & "^FS" & vbCrLf
        Else
            m_strLineItem = m_strLineItem & "^FO20,20^A0N,250,125^FWN^FH^FD" & objTable.Records(0).Fields("3059").Value & "^FS" & vbCrLf
        End If
    End If
        
    Exit Sub
EH:
    MsgBox "Error in ZplCustomLabel, " & Err.Source & ", " & Err.Description, vbSystemModal
        
End Sub
'

Private Sub Cafe_AfterShipment(ByVal ShipmentNumber As String, ByVal IsInternational As Boolean)
'------------------------------------------------
'Author: Domonic Grande emp# 396671
'Called From: FSM Cafe Event
'Desc: Event fires after the shipment is complete
'------------------------------------------------
    On Error GoTo EH
   
    ' 2011-11-28, JFW, Cafe labels.
    If True Then
        
        '----------------------------------------------------------
        'calls custom label program to see if any labels need to be
        'printed at the shipment level
        '----------------------------------------------------------
        
        ' Logfile "EightInchLabel.Cafe.Cafe_AfterShipment, tracking number " & ShipmentNumber
        
        m_dtCleanup = Now
        If timerCleanup Is Nothing Then Set timerCleanup = New Timer
        timerCleanup.Interval = 500
        timerCleanup.Enabled = True
        
        Call modLabel8.EventAfterShipment(m_strTrackingNumber)
    
    End If
    
    g_boolAfterLabel = True
    m_strTrackingNumber = ""
    
    Exit Sub
EH:
    MsgBox Err.Description & " " & Err.Number, vbCritical, "EightInchLabel.Cafe.AfterShipment"

End Sub
'

Private Sub Cafe_AfterShipPackage(ByVal TrackingNumber As String, ByVal Meter As String, _
                                  ByVal IsInternational As Boolean)
   
'-------------------------------------
'Author: Domonic Grande emp# 396671
'Called From: FSM Cafe Event
'Desc: Event fires after package ships
'-------------------------------------
    On Error GoTo EH:
    
    ' First piece tracking number
    If m_strTrackingNumber = "" Then m_strTrackingNumber = TrackingNumber
        
    ' 2011-11-28, JFW, turn off.
    If True Then
    
        ' Logfile "EightInchLabel.Cafe.Cafe_AfterShipPackage, tracking number " & TrackingNumber
        
        m_dtCleanup = Now
        
        ' On first use make Shipper sig reqd true
        If Not boolSigReqdStarted Then
            boolSigReqdStarted = True
            boolSigReqdShipper = True
        End If
        ' All express labels get sig reqd
        If Cafe1.Meter = "123456" Then
            If Len(TrackingNumber) < 15 Then
                boolSigReqdIntegration = True
            Else
                boolSigReqdIntegration = False
            End If
        Else
            If Len(TrackingNumber) < 15 Then
                boolSigReqdIntegration = True
            Else
                boolSigReqdIntegration = False
            End If
        End If
        
        If Canadian_BBB Then
            ' CA Standard BBB label
            Dim objTable As Table
            Breathe
            Set objTable = Cafe1.Databases.Shipment("19,25,29,2407,3001,3002,3059").Lookup(TrackingNumber)
            With m_udtBedBathBeyond
                .SSCC18 = objTable.Records(0).Fields("25").Value
                If objTable.Records(0).Fields("2407").Value <> "" Then
                    .StoreNumber = objTable.Records(0).Fields("2407").Value
                Else
                    .StoreNumber = objTable.Records(0).Fields("19").Value
                End If
                .PoNumber = objTable.Records(0).Fields("3001").Value
                .VendorNumber = objTable.Records(0).Fields("3059").Value
            End With
        End If
        
        '--------------------------
        'Calls custom label program
        '--------------------------
        ' modLabel8.GetVals TrackingNumber, Meter, IsInternational, , False, "Var Holding Message Field Here", False
        modLabel8.GetVals TrackingNumber, Meter, IsInternational, , False, m_strMessage, "Var Holding SSCC18 Here", "Var Holding SortId Here", False
    
    End If
    
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical Or vbSystemModal, "EightInchLabel.Cafe.AfterShip"
    
End Sub
'

Private Sub Cafe_BeforeShipPackage()
'---------------------------------------------------------------
'Author: Domonic Grande emp# 396671
'Called From: FSM Cafe Event
'Desc: Event fires after f10 is pressed but before package ships
'---------------------------------------------------------------

On Error GoTo EH
    '------------------------------
    'Checks to see if identical mps
    '------------------------------
    ' 2007-11-22, JFW, This code in here because Cafe to turn on CI when doing TD
    ' Call modLabel8.EventBeforeShipPackage

    Exit Sub
EH:
      MsgBox Err.Description & " " & Err.Number, vbCritical, "EightInchLabel.Cafe.BeforeShipPackage"

End Sub
'

' 2008-10-01, JFW, Clear pick label, on Cafe clear screen.
Private Sub Cafe_ClearFields()

    Call ClearPickLabel
     
End Sub
'

Private Sub Cafe_SystemKeyPress(ByVal KeyName As String)
    On Error Resume Next
    
    Dim i As Long
    
    Select Case KeyName
'        Case Is = "Cntrl+F3"
'            ' On first use make Shipper sig reqd true
'            If Not boolSigReqdStarted Then
'                boolSigReqdStarted = True
'                boolSigReqdShipper = True
'            End If
'            ' Toggle Shipper wants sig reqd
'            boolSigReqdShipper = Not boolSigReqdShipper
'            MsgBox "Signature required labels are " & IIf(boolSigReqdShipper, "on", "off") & ".", vbSystemModal
        Case Is = "Cntrl+F12"
            frmLabelConfig.Show
            i = Window.SetTopMost(frmLabelConfig)
            Window.SetFocus (i)
    End Select

End Sub
'




Private Sub timerCleanup_Execute()
'
    On Error GoTo ErrorExit
    
    If Now > DateAdd("s", 2, m_dtCleanup) Then
        timerCleanup.Enabled = False
        modLabel8.GetVals "", "", False, , False, "", "", "", False
        Call modLabel8.EventAfterShipment
    End If
    Exit Sub
    
ErrorExit:
    
End Sub


